package com.ffe.flower.engine.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

import com.ffe.flower.engine.constant.AuditStatus;

@Entity
@Table(name = "FLOW_STATE_DETAIL", indexes = { @Index(columnList = "FLOW_ID") })
public final class FlowStateDetail {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "STATE_ID")
  private Integer stateId;

  @Column(name = "FLOW_STATE", length = 20, nullable = false)
  @Enumerated(EnumType.STRING)
  private Enum<?> flowState;

  @Column(name = "FLOW_ID", nullable = false)
  private Integer flowId;

  @Column(name = "AUDIT_STATUS", length = 20, nullable = false)
  @Enumerated(EnumType.STRING)
  private AuditStatus auditStatus;

  @Column(name = "AUDITOR_ID", length = 32)
  private String auditorId;

  @Column(name = "AUDITOR_AGENT")
  private Boolean auditorAgent;

  @Column(name = "REMARK", length = 100)
  private String remark;

  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "CREATED_DATE", nullable = false)
  private Date createdDate;

  @Temporal(TemporalType.TIMESTAMP)
  @Column(name = "LAST_MODIFIED_DATE", nullable = false)
  private Date lastModifiedDate;

  @Version
  private long version;

  @PrePersist
  public void onPrePresist() {
    this.createdDate = this.lastModifiedDate = new Date();
  }

  @PreUpdate
  public void onPreUpdate() {
    this.lastModifiedDate = new Date();
  }

  public Integer getFlowId() {
    return stateId;
  }

  public void setFlowId(Integer flowId) {
    this.stateId = flowId;
  }

  public Enum<?> getFlowState() {
    return flowState;
  }

  public void setFlowState(Enum<?> flowState) {
    this.flowState = flowState;
  }

  public AuditStatus getAuditStatus() {
    return auditStatus;
  }

  public void setAuditStatus(AuditStatus auditStatus) {
    this.auditStatus = auditStatus;
  }

  public String getRemark() {
    return remark;
  }

  public void setRemark(String remark) {
    this.remark = remark;
  }

  public Date getCreatedDate() {
    return createdDate;
  }

  public void setCreatedDate(Date createdDate) {
    this.createdDate = createdDate;
  }

  public String getAuditorId() {
    return auditorId;
  }

  public void setAuditorId(String auditorId) {
    this.auditorId = auditorId;
  }

  public Boolean getAuditorAgent() {
    return auditorAgent;
  }

  public void setAuditorAgent(Boolean auditorAgent) {
    this.auditorAgent = auditorAgent;
  }

  public Date getLastModifiedDate() {
    return lastModifiedDate;
  }

  public void setLastModifiedDate(Date lastModifiedDate) {
    this.lastModifiedDate = lastModifiedDate;
  }

  public Integer getStateId() {
    return stateId;
  }

  public void setStateId(Integer stateId) {
    this.stateId = stateId;
  }
}
